<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtatomfeed.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class RouteExpenseCreate extends Page
{
       public $hfError = null;
       public $JSValidate = null;
       public $lblamt = null;
       public $Label12 = null;
       public $imgBack = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $edAccount = null;
       public $btnAddAccount = null;
       public $btnDelAccount = null;
       public $listAccount = null;
       public $JTDivAccount = null;
       public $JTGroupBox2 = null;
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $btnShowAccount = null;
       public $JTJavaScript6 = null;
       public $JTJavaScript5 = null;
       public $JTJavaScript4 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $compid = null;
       public $btnShowType = null;
       public $dpDate = null;
       public $Label1 = null;
       public $memoDesc = null;
       public $hiddenEmp = null;
       public $hiddenRoute = null;
       public $lblDesc = null;
       public $cmbAccount = null;
       public $lblAccount = null;
       public $cmbType = null;
       public $lblType = null;
       public $edAmount = null;
       public $lblAmount = null;
       public $Image3 = null;
       public $JTSiteTheme1 = null;
       function edAmountJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edAmount','lblamt');
       <?php

       }

       function RouteExpenseCreateJSLoad($sender, $params)
       {
       $this->clr_ex();
       ?>
       //Add your javascript code here

       <?php

       }


       function btnDelAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var AccountIndex = document.getElementById('listAccount').selectedIndex;
       var AccountValue = document.getElementById('listAccount')[AccountIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxAccount3(AccountValue,compider3);
       <?php

       }

       function btnAddAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addaccount = document.getElementById('edAccount').value;
       var compider = document.getElementById('compid').value;
       AjaxAccount2(addaccount,compider);
       document.RouteExpenseCreate.edAccount.value = " ";

       <?php

       }

       function btnShowAccountJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivAccount').Show();
       <?php

       }


       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxType3(TypeValue,compider3);
       <?php

       }

       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var compider = document.getElementById('compid').value;
       AjaxType2(addtype,compider);
       document.RouteExpenseCreate.edType.value = " "
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnCancelClick($sender, $params)
       {
        redirect('route_expense_list.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());
       }

       function clr_ex()
       {
       $this->cmbAccount->Clear();
       $this->cmbAccount->AddItem('--Select--', null, null);
       $this->cmbAccount->setItemIndex('--Select--', null, null);
       $result_account = mysql_query("SELECT * FROM lookup_expense_tbl WHERE category='accounts' AND company_id='".$_SESSION['company_id']."'");

       while($row_account = mysql_fetch_array($result_account))
       {
       $this->cmbAccount->AddItem($row_account['value'], null, $row_account['value']);
       }

       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $this->cmbType->setItemIndex('--Select--', null, null);
       $result_type = mysql_query("SELECT * FROM lookup_expense_tbl WHERE category='types' AND company_id='".$_SESSION['company_id']."'");

       while($row_type = mysql_fetch_array($result_type))
       {
       $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
       }
       $this->dpDate->Text = date('Y-m-d');
       $this->memoDesc->Text="";
       $this->edAmount->Text="";

       }


       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr This field is required &darr';
             $this->hfError->setValue('1');
          }
       }

       function RouteExpenseCreateCreate($sender, $params)
       {
       $this->hfError->setValue('0');
       $this->lblamt->Caption = '';

       $this->compid->Value = $_SESSION['company_id'];
       $emp = $_GET['emp'];
       $route = $_GET['route'];
       $this->hiddenEmp->setValue($emp);
       $this->hiddenRoute->setValue($route);
       $this->imgBack->setLink('route_expense_list.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());

       $this->cmbAccount->Clear();
       $this->cmbAccount->AddItem('--Select--', null, null);
       $result_account = mysql_query("SELECT * FROM lookup_expense_tbl WHERE category='accounts' AND company_id='".$_SESSION['company_id']."'");

       while($row_account = mysql_fetch_array($result_account))
       {
       $this->cmbAccount->AddItem($row_account['value'], null, $row_account['value']);
       }

       //list account
       $this->edAccount->Text = "";
       $result_a = mysql_query("SELECT * FROM lookup_expense_tbl WHERE category='accounts' AND company_id='".$_SESSION['company_id']."'");

       while($row_a = mysql_fetch_array($result_a))
       {
       $this->listAccount->AddItem($row_a['value'], null, $row_a['value']);
       }


       $this->cmbType->Clear();
       $this->cmbType->AddItem('--Select--', null, null);
       $result_type = mysql_query("SELECT * FROM lookup_expense_tbl WHERE category='types' AND company_id='".$_SESSION['company_id']."'");

       while($row_type = mysql_fetch_array($result_type))
       {
       $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
       }

       //list type
       $this->edType->Text = "";
       $result_t = mysql_query("SELECT * FROM lookup_expense_tbl WHERE category='types' AND company_id='".$_SESSION['company_id']."'");

       while($row_t = mysql_fetch_array($result_t))
       {
       $this->listType->AddItem($row_t['value'], null, $row_t['value']);
       }
       $this->dpDate->Text = date('Y-m-d');
       $this->memoDesc->Text="";
       $this->edAmount->Text="";
       }

       function btnSubmitClick($sender, $params)
       {
       $this->validateRequired($this->edAmount->Text, 'lblamt');
       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {

       $veh = mysql_query("select * from route_tbl where route_id = '".$this->hiddenRoute->getValue()."'");
       $result_veh = mysql_fetch_array($veh);

       $result = mysql_query("INSERT INTO rou_expense_tbl (company_id,
       emp_id,
       route_id,
       amount,
       type,
       account,
       description,
       date)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$this->hiddenEmp->getValue()."',
       '".$this->hiddenRoute->getValue()."',
       '".$this->edAmount->Text."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->cmbAccount->getItemIndex()."',
       '".$this->memoDesc->Text."',
       '".$this->dpDate->Text."')") or die ('INSERT ROUTE EXPENSE - ' . mysql_error());


       mysql_query("INSERT INTO veh_expense_tbl(company_id,
       vehicle_id,
       type,
       amount,
       date,
       account,
       description)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$result_veh['veh_id']."',
       '".$this->cmbType->getItemIndex()."',
       '".$this->edAmount->Text."',
       '".$this->dpDate->Text."',
       '".$this->cmbAccount->getItemIndex()."',
       '".$this->memoDesc->Text."')") or die ('INSERT VEH EXPENSE - ' . mysql_error());


       redirect('route_expense_list.php?emp='.$this->hiddenEmp->getValue().'&route='.$this->hiddenRoute->getValue());
       }
       }


}

global $application;

global $RouteExpenseCreate;

//Creates the form
$RouteExpenseCreate=new RouteExpenseCreate($application);

//Read from resource file
$RouteExpenseCreate->loadResource(__FILE__);

//Shows the form
$RouteExpenseCreate->show();

?>